<template>
	<view class="pageview">
		<cl-navbar :title="user_info.is_set_password == '0'?$t('my_file.privacySecurity.index.changePassword'):$t('my_file.privacySecurity.index.setPassword')" leftIconSize="40rpx" placeholder autoBack>
		</cl-navbar>
		<view style="padding:30rpx;">
			<u-input
				v-if="user_info.is_set_password != '0'"
				:customStyle="{backgroundColor:'#1E1F30',height:'110rpx',padding:'0 30rpx',borderRadius: '20rpx'}"
				:placeholder="$t('my_file.privacySecurity.index.inputoldpsd')"
				fontSize="28rpx"
				color="#ffffff"
				border="none"
				type="password"
				password
				clearable
				v-model="passwordData.old_pwd"
			  ></u-input>
			<u-input
				style="margin-top: 20rpx;"
				:customStyle="{backgroundColor:'#1E1F30',height:'110rpx',padding:'0 30rpx',borderRadius: '20rpx'}"
				:placeholder="$t('my_file.privacySecurity.index.inputnewpsd')"
				fontSize="28rpx"
				color="#ffffff"
				border="none"
				type="password"
				password
				clearable
				v-model="passwordData.new_pwd"
			  ></u-input>
			<u-input
				style="margin-top: 20rpx;"
				:customStyle="{backgroundColor:'#1E1F30',height:'110rpx',padding:'0 30rpx',borderRadius: '20rpx'}"
				:placeholder="$t('my_file.privacySecurity.index.verifypsd')"
				fontSize="28rpx"
				color="#ffffff"
				border="none"
				type="password"
				password
				clearable
				v-model="passwordData.re_new_pwd"
			  ></u-input>
			  <view class="okText" @click="completePopPassword">
				  {{$t("common.okText")}}
			  </view>
		</view>
		</view>
	</view>
</template>

<script>
	import userApi from "@/services/api/user.js"
	import {
		mapState
	} from 'vuex'
	export default {
		name: 'changePassword',
		data() {
			return {
				passwordData:{
					old_pwd:'',
					new_pwd:'',
					re_new_pwd:''
				}
			}
		},
		computed: {
			...mapState({
				user_info: state => state.user.user_info,
			})
		},
		onLoad() {
		},
		methods: {
			//确认修改密码
			async completePopPassword(){
				console.log(1111);
				try{
					let updata = JSON.parse(JSON.stringify(this.passwordData))
					console.log(2222);
					let apires = null
					console.log(33333);
					if(this.user_info.is_set_password == '0'){
						delete updata.old_pwd
						apires = await uni.$api.user.firstChangePassword(updata)
					}else{
						apires = await uni.$api.user.changePassword(updata)
					}
					if(apires && apires.code == 200){
						
						uni.showToast({
							title:this.$t("request.success.edit"),
							icon:"none"
						})
						setTimeout(()=>{
							this.$store.dispatch('uploadUserInfo', {
								"is_set_password":'1'
							})
							this.passwordData = {
								old_pwd:'',
								new_pwd:'',
								re_new_pwd:''
							}
							this.$Router.back()
						},1000)
					}
				}catch(e){
					//TODO handle the exception
				}
			}
		},
	};
</script>

<style scoped lang="scss">
	.okText{
		margin: 100rpx auto 0;
		width: 500rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		font-size: 32rpx;
		color: #FFFFFF;
		background: linear-gradient( 270deg, #FF7B3C 0%, #FF5B7C 100%);
		border-radius: 40rpx;
	}
	.cellviewGrop {
		background: #1E1F30;
		border-radius: 20rpx;
		margin: 20rpx 30rpx 0;
	
		.cellview {
			display: flex;
			justify-content: space-between;
			padding: 0 30rpx;
			height: 110rpx;
	
			&__left {
				display: flex;
				align-items: center;
	
	
				&__title {
					font-size: 28rpx;
					color: #FFFFFF;
				}
			}
			&__right{
				display: flex;
				align-items: center;
				&__content{
					font-size: 28rpx;
					color: #61626e;
				}
			}
		}
	}
</style>